package net.aiion.weave.impl.bytecode;

import net.aiion.weave.spi.bytecode.BytecodeFinder;
import net.aiion.weave.spi.bytecode.BytecodeGenerator;
import net.aiion.weave.spi.bytecode.BytecodeSource;
import net.aiion.weave.spi.bytecode.BytecodeSourceFactory;
import net.aiion.weave.spi.resources.Resource;
import net.aiion.weave.spi.resources.ResourceFactory;

public class BytecodeSourceFactoryImpl implements BytecodeSourceFactory
{
    public BytecodeSourceFactoryImpl() {
    }

    @Override
    public BytecodeSource createReader(final String aClassName) {
        return createReader(createResource(aClassName));
    }

    @Override
    public BytecodeSource createReader(final Resource aResource) {
        return new BytecodeReaderImpl(aResource);
    }

    @Override
    public BytecodeFinder createFinder(final String aClassName) {
        return createFinder(createResource(aClassName));
    }

    @Override
    public BytecodeFinder createFinder(final Resource aResource) {
        return new BytecodeFinderImpl(aResource);
    }

    private Resource createResource(final String aClassName) {
        return ResourceFactory.getInstance().createResource(aClassName.replace('.', '/') + ".class");
    }

    @Override
    public BytecodeGenerator createGenerator() {
        return new BytecodeGeneratorImpl();
    }
}
